package com.example.campuslink.commen.db.comment

import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.TypeConverters
import db.ListStringConverter
import java.io.Serializable

@Entity(tableName = "comment_table", primaryKeys = ["id", "commentUserNumber"])
//@TypeConverters(ListStringConverter::class)
data class CommentTable(
    var id: Int = 0,
    var commentContent: String = "",
    var commentUserNumber: String = "",
    var handUserNumber: String = "",
    var data: Long = 0,
    var contentImage: String = "",
    @TypeConverters(ListStringConverter::class)
    var loveNumber: MutableList<String> = mutableListOf()
) : Serializable {
    @Ignore
    constructor() : this(
        id = 0,
        commentContent = "",
        commentUserNumber = "",
        handUserNumber = "",
        data = 0,
        contentImage = ""
    )

    companion object {
        suspend fun insertWithId(
            dao: CommentDao,
            comment: CommentTable
        ) {
            val maxId = dao.getMaxId() ?: 0
            dao.insertComment(comment.copy(id = maxId + 1))
        }
    }
}